﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace ContentPipelineExtension
{
    /// <summary>A map is a single .tmx file from Tiled Map Editor. The XML for this item should contain:
    /// - File path to .tmx 
    /// - Vector2 indicating the position within the MapCollection grid to place this map (makes up a level)
    /// - Optional: Which type of bullet spawner should be used on this map (BulletML .xml file name)
    /// - A list of Events that this map owns
    /// </summary>
    public class MapXmlContent
    {
        public String Path;
        public Vector2 GridPosition = Vector2.Zero;

        [ContentSerializer(Optional = true)]
        public String BulletSpawner;

        public List<MapEventXmlContent> Events = new List<MapEventXmlContent>();
    }

    /// <summary>A map event is a series of waves that will spawn enemies and perform other map trigger actions. The XML for this item should contain:
    /// - The time between each wave in this event measured in seconds
    /// - A list of Waves that make up this event
    /// - Optional: A list of map triggers that will fire based on this event
    /// </summary>
    public class MapEventXmlContent
    {
        public int SecondsBetweenWaves;
        public List<MapEventWaveXmlContent> Waves = new List<MapEventWaveXmlContent>();

        [ContentSerializer(Optional = true)]
        public List<TriggerXmlContent> Triggers = new List<TriggerXmlContent>();
    }

    /// <summary>A map event wave is a series of enemies that are spawned in succession to populate the map. The XML for this item should contain:
    /// - The time between each enemy spawn in this wave measured in milliseconds
    /// - A list of enemies that are spawned in this wave
    /// </summary>
    public class MapEventWaveXmlContent
    {
        public int MillisecondsBetweenEnemies;
        public List<EnemyEntityXmlContent> Enemies = new List<EnemyEntityXmlContent>();
    }

    /// <summary>An enemy is a single entity that attempts to attack the player. Enemies are spawned in waves. The XML for this item should contain:
    /// - The type of the enemy (relates to the EntityId for the EnemyEntity factory to generate the correct enemy type)
    /// - The count of the enemy to spawn in this wave
    /// - Whether or not the enemies spawned in this batch are equipped with weapons
    /// - Optional: An id referencing the path for the enemies to follow when they are spawned (the id of paths is maintained in the .tmx)
    /// </summary>
    public class EnemyEntityXmlContent
    {
        public int Type;
        public int Count;
        public bool HasWeapon;

        [ContentSerializer(Optional = true)]
        public int Path;
    }

    /// <summary>A trigger is a map callback that fires based on some time in a map event. Triggers can have actions to perform such as "Open" or "SpawnItem". The XML for this item should contain:
    /// - The type of the trigger such as "OnComplete" which will fire the trigger when the event it belongs to completes
    /// - A list of actions to perform when the trigger fires
    /// </summary>
    public class TriggerXmlContent
    {
        public string Type;
        public List<TriggerActionXmlContent> Actions = new List<TriggerActionXmlContent>();
    }

    /// <summary>An action is a specific thing that should happen when the trigger fires. Actions have one to many subscribers that will be affected based on the action's type. The XML for this item should contain:
    /// - The type of the action to perform such as "Open" or "SpawnItem"
    /// - A list of id values that relate to some subscriber object maintained in the .tmx (map objects)
    /// </summary>
    public class TriggerActionXmlContent
    {
        public string Type;

        [ContentSerializer(Optional = true)]
        public int EntityId;

        [ContentSerializer(Optional = true)]
        public int Path;

        public List<int> SubscriberIds = new List<int>();
    }
}
